js appendchild wait for callback

105

js appendchild wait for callback -

function injectScript(src,callback){
	var script = document.createElement('script');
        script.src = src;
        script.onload=function(){
            callback();
        }
        document.head.appendChild(script);
}
injectScript('https://www.mysite.com/somescript.js', function(){
	//the script is now all loaded
});

Comments

Submit
0 Comments